/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.infonova.education.microservice.repository.entity;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Stefan
 */
@Entity
@Table(name = "ordera")
@XStreamAlias("order")
public class Order {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "order_id")
    private long orderId;

    private long customerId;

    @OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
    private Set<OrderPosition> positions;

    public Order() {
        positions = new HashSet<>();
    }

    
    public Order(long customerId) {
        this.customerId = customerId;
        positions = new HashSet<>();
    }
    public Order(long customerId, Set<OrderPosition> positions) {
        this.customerId = customerId;
        this.positions = positions;
    }

    public long getOrderId() {
        return orderId;
    }

    public long getCustomerId() {
        return customerId;
    }

    public void setPositions(Set<OrderPosition> positions) {
        this.positions = positions;
    }

    public Set<OrderPosition> getPositions() {
        return positions;
    }

    public void setOrderId(long orderId) {
        this.orderId = orderId;
    }

    public void setCustomerId(long customerId) {
        this.customerId = customerId;
    }

//    public long calculateTotalPrice() {
//        long price = 0;
//        for (OrderPosition position : positions) {
//            Product product = position.getProduct();
//            price += product.getPrice() * position.getAnzahl();
//        }
//        return price;
//    }
}
